/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * boolean.c
 */

#include "../basic/operator.h"

// (make-boolean 1)
// (make-boolean 0)
Cell* op_make_boolean(Scheme *sc) {
	Cell* x = first(sc->args);
	TYPE_CHECK(sc, x, INTEGER_TYPE);
	long boolValue = x->_longValue;
	if (boolValue == 1) {
		sc->returnValue = &g_true;
	} else if (boolValue == 0) {
		sc->returnValue = &g_false;
	} else {
		sc->returnValue = make_default_exception(sc, "NOT_A_BOOLEAN", "You should input 0 or 1.");
	}
	return pop_callstack(sc);
}

void init_boolean_constants(Scheme *sc) {
	add_constant(sc, CONSTANT_NAME_TRUE, &g_true);
	add_constant(sc, CONSTANT_NAME_FALSE, &g_false);
}

void init_boolean_operators(Scheme *sc) {
	ADD_OPERATOR(sc, "make-boolean", make_boolean);
}
